package com.songshuai.webapi.permission.common.enumerations;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum DepartmentLevelTypeEnum {
    Campus(6001001, "校区");
    private int code;
    private String msg;

    DepartmentLevelTypeEnum(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return DepartmentLevelTypeEnum.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public static String getMsg(String define){
        try {
            return DepartmentLevelTypeEnum.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(int code){
        for(DepartmentLevelTypeEnum err : DepartmentLevelTypeEnum.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "errorCode not defined ";
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
}
